package cn.bone.netty01;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

/**
 * Created by superbone on 2016/9/9.
 */
public class ChildChannelHandler extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        System.out.println("信息:有一个客户端连接到本服务器端");
        System.out.println("IP:"+socketChannel.localAddress().getHostName());
        System.out.println("port:"+socketChannel.localAddress().getPort());


        //解码器
        //基于换行符号
        socketChannel.pipeline().addLast(new LineBasedFrameDecoder(1024));
        //解码转string
        socketChannel.pipeline().addLast(new StringDecoder());

        //在管道中添加我们自己的接收数据实现方法
        socketChannel.pipeline().addLast(new TimeServerHandler());
    }
}
